package com.accelstack.cmp.service;

import com.accelstack.cmp.entity.Memory;
import com.accelstack.cmp.repository.MemoryRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Optional;

/**
 * 内存Service
 */
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class MemoryService {
    
    private final MemoryRepository memoryRepository;
    
    @Transactional
    public Memory create(Memory memory) {
        return memoryRepository.save(memory);
    }
    
    @Transactional
    public Memory update(Memory memory) {
        return memoryRepository.save(memory);
    }
    
    @Transactional
    public void deleteById(Long id) {
        memoryRepository.deleteById(id);
    }
    
    public Optional<Memory> findById(Long id) {
        return memoryRepository.findById(id);
    }
    
    public List<Memory> findAll() {
        return memoryRepository.findAll();
    }
    
    public Page<Memory> findAll(Pageable pageable) {
        return memoryRepository.findAll(pageable);
    }
    
    public List<Memory> findByServerId(Long serverId) {
        return memoryRepository.findByServerId(serverId);
    }
}

